/**
* @Author: Devin
* @Date: 2018-09-10 19:38:56
* @Author Email by: 3481653@gmail.com
* @Last Modified time: 2018-09-10 19:38:56
*/

import request from '@/utils/request'

export function merchantInit(agent_num, saleman_num) {
  return request({
    url: 'agent/sales_busin/get_busin_saleman',
    method: 'GET',
    params: { agent_num, saleman_num }
  })
}

export function ToggleType(type) {
  return request({
    url: '/merchant/id_types',
    method: 'GET',
    params: { type }
  })
}

/**
 * 文件上传
 * @param {Object} data 文件数据
 * @param {*} _this 全局this指向
 */
export function uploade(data, _this) {
  return request({
    url: '/merchant/uploadCommer',
    headers: { 'Content-Type': 'multipart/form-data' },
    onUploadProgress: progressEvent => {
      _this.$loading(true, progressEvent.loaded / progressEvent.total * 100 | 0)
      if (progressEvent.loaded / progressEvent.total * 100 | 0 === 100) {
         _this.$loading(false, 0)
      }
    },
    method: 'POST',
    data
  })
}

/**
 * 网商银行支行远程搜索
 * @param {String} bankno 查询参数
 */
export function remoteMethodQuery(bankno) {
  return request({
    url: 'agent/sales_busin/bank_no',
    method: 'GET',
    params: { bankno }
  })
}


/**
 * 地区获取
 */
export function areaAddress() {
  return request({
    url: '/merchant/area_lists',
    method: 'GET'
  })
}

/**
 * 开户行远程搜索
 */
export function GetSearchBankList(name) {
  return request({
    url: '/agent/sales_busin/get_bank_name',
    method: 'GET',
    params: { name }
  })
}


/**
 * 商户入驻银行账户资料更新
 * @param {Number} merchant_num 商户编号
 * @param {Number} agent_num 代理商编号
 * @param {Number} sale_num 业务员编号
 */
export function merchantBankUpdate(merchant_num, agent_num, sale_num, token, date) {
  const data = {
    merchant_num,
    agent_num,
    sale_num,
    token,
    bank: {
      leader_type: date.leader_type,
      bank_idcard_1: date.leader_id_1,
      bank_idcard_2: date.leader_id_2,
      leader_id_3: date.leader_id_3,
      // bank_certi_inhand: date.bank_certi_inhand,
      bank_account_type: date.bank_account_type,
      bank_account_name: date.bank_account_name,
      bank_account_no: date.bank_account_no,
      bank_code: date.bank_code,
      bank_id_card_expire: date.bank_id_card_expire,
      bank_branch_name: date.bank_branch_name,
      bank_branch_code: date.bank_branch_code,
      bank_address: date.bank_address,
      bank_pre_mobile: date.bank_pre_mobile,
      bank_id_card_addr: date.bank_id_card_addr,
      bank_id_card_no: date.bank_id_card_no,
      bank_id_card_type: date.bank_id_card_type,
      bank_permit: date.bank_permit,
      // bank_certi: date.bank_certi,
      bank_card_inhand: date.bank_head,
      bank_card: date.bank_card,
      mod: 2
    },
    info: {},
    leader: {},
    contact: {},
    wx: {}
  }
  return request({
    url: 'agent/sales_busin/update_merchant',
    method: 'POST',
    data
  })
}

/**
 * 商户基础资料入驻
 * @param {Object} date 入驻资料
 * @param {Object} agent 入驻资料
 */
export function merchant_add(date, agent_num, token, sale_num) {
  const data = {
    mod: 1,
    sale_num,
    agent_num,
    token,
    type: date.merchant_type,
    full_name: date.full_name,
    short_name: date.short_name,
    service_phone: date.service_phone,
    real_address: date.real_address,
    bus_licence_type: date.bus_licence_type,
    alipay_name: date.alipay_name,
    alipay_account: date.alipay_account,
    bus_licence_no: date.bus_licence_no,
    bus_licence_expire: date.bus_licence_expire,
    bus_licence: date.bus_licence,
    store_face: date.store_face,
    store_canyin_plat: date.store_canyin_plat,
    store_counter: date.store_counter,
    store_space: date.store_space,
    bus_licence_oth: date.bus_licence_oth,
    bus_lease_agreement: date.bus_lease_agreement,
    bus_licence_reg_date: date.bus_licence_reg_date,
    name: date.username,
    password: date.password
  }
  return request({
    url: 'agent/sales_busin/create_merchant',
    method: 'POST',
    data
  })
}


/**
 * 商户入驻负责人信息资料更新
 * @param {Number} merchant_num 商户编号
 * @param {Number} user_num 代理商编号
 * @param {Object} date 数据
 */
export function merchantPrincipalUpdate(merchant_num, agent_num, sale_num, token, date) {
  const data = {
    merchant_num,
    sale_num,
    token,
    agent_num,
    info: {},
    bank: {},
    leader: {
      leader_type: date.leader_type,
      leader_name: date.leader_name,
      leader_id_expire: date.leader_time,
      leader_phone: date.leader_phone,
      leader_id_no: date.leader_id_no,
      leader_id_type: date.leader_id_type,
      leader_id_1: date.leader_id_1,
      leader_id_2: date.leader_id_2,
      leader_id_3: date.leader_id_3,
      mod: 3
    },
    contact: {},
    wx: {}
  }
  return request({
    url: 'agent/sales_busin/update_merchant',
    method: 'POST',
    data
  })
}


/**
 * 商户入驻联系人信息资料更新
 * @param {Number} merchant_num 商户编号
 * @param {Number} user_num 代理商编号
 * @param {Object} date 提交参数
 */
export function merchatnContactUpdate(merchant_num, agent_num, sale_num, token, date) {
  const data = {
    merchant_num,
    agent_num,
    sale_num,
    info: {},
    token,
    wx: {},
    bank: {},
    leader: {},
    contact: {
      contact_name: date.contact_name,
      contact_phone: date.contact_phone,
      contact_id_no: date.contact_id_no,
      contact_duties: date.contact_duties,
      contact_email: date.contact_email,
      contact_weixin: date.contact_weixin,
      cantact_alipay: date.cantact_alipay,
      contact_qq: date.contact_qq
    }
  }
  return request({
    url: 'agent/sales_busin/update_merchant',
    method: 'POST',
    data
  })
}